// Copyright (c) Appeon. All rights reserved.
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. 
// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.

using System;
using Antlr4.Runtime.Tree;
using Microsoft.Extensions.DependencyInjection;

namespace SnapObjects.Expressions
{
    internal abstract class NodeExpressionVisitor<TResult, TContext>
         : INodeExpressionVisitor<TResult>
        where TContext : IParseTree
    {
        protected readonly IServiceProvider _services;
        protected readonly IPolicyProvider<TResult> _provider;

        public NodeExpressionVisitor(IServiceProvider services)
        {
            _services = services;
            _provider = services.GetService<IPolicyProvider<TResult>>();

            this.NodeType = typeof(TContext);
        }

        public Type NodeType { get; }

        public virtual TResult Visit(
            IExpressionVisitor<TResult> treeVisitor,
            IParseTree context,
            ParserOptions<TResult> options)
        {
            return this.Visit(treeVisitor, (TContext)context, options);
        }

        public virtual TResult Visit(
            IExpressionVisitor<TResult> treeVisitor,
            TContext context,
            ParserOptions<TResult> options)
        {
            return default;
        }
    }
}
